import unittest
from selenium import webdriver
from time import sleep
from Unit_10.Page.Page1 import Page1
from Unit_10.Page.Page2 import Page2
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait

class TestCase(unittest.TestCase):
    # 初始化驱动
    def setUp(self):
        self.driver = webdriver.Edge()
        self.driver.maximize_window()


    def tearDown(self):
        sleep(5)
        self.driver.quit()

    # 添加收货地址
    def test_jiuxian_01(self):
        p = Page2(self.driver)
        p.open_url('https://www.jiuxian.com/')
        p.login()
        dy_userlogin = self.driver.find_element(By.CLASS_NAME,'userLogin.on').text
        self.assertEqual('帐号登录',dy_userlogin)
        p.denglu()
        sleep(10)
        p.login_btn()
        p.login_sure()
        try:
            WebDriverWait(self.driver, 20, 0.5).until(lambda driver: self.driver.find_element('/html/body/div[2]/div/div[1]/div/p/span').is_displayed())
            dy_username = self.driver.find_element(By.XPATH, '/html/body/div[2]/div/div[1]/div/p/span').text
            self.assertEqual('jxw385236693', dy_username)
        except Exception as e:
            print('未找到元素------',e)
        p.jiuxian()
        p.new_window()
        p.scroll_x(900)
        p.address()
        p.add_address()
        p.people()
        p.province()
        p.city()
        p.district()
        p.address_text()
        p.phone()
        p.save()
        p.save_sure()



if __name__ == '__main__':
    unittest.main()

